#ifndef H_C_PROTOCOL_DELEGATE_H
#define H_C_PROTOCOL_DELEGATE_H

#include "../typedefine.h"
#include <memory>
#include <vector>
#ifndef _USING_CLI
#include <functional>
#endif
#include "SProtocolEndPoint.h"
#include "SProtocolUID.h"
#include "SRpcRet.h"

namespace QWER
{
	QINTERFACE IProtocolHelper;
	QCLASS IProtocol;
	QCLASS IRunner;
	QCLASS IRpcData;
	QCLASS CProtocolServiceFrontend;
    QCLASS CServiceBackendHelper;
    QINTERFACE IProtocolChannel;
    QCLASS CProtocolHeader;

#ifdef _USING_CLI

    QDLL_EXPORT delegate void DOnProtocolEndPointConnect(CONST_REF(SProtocolEndPoint) rsSrcEndPoint, CONST_REF(SProtocolEndPoint) rsDstEndPoint);
    QDLL_EXPORT delegate void DOnProtocolEndPointDisConnect(CONST_REF(SProtocolEndPoint) rsSrcEndPoint, CONST_REF(SProtocolEndPoint) rsDstEndPoint);
    QDLL_EXPORT delegate void DOnProtocolChannelAccepted(UINT64 qwChannelUID);
    QDLL_EXPORT delegate PTR_OR_REF(IProtocolHelper) DNewProtocolHelper(PTR_OR_REF(IRunner) roRunner);
    QDLL_EXPORT delegate void DOnProtocolChannelClosed(UINT64 qwChannelUID);
	QDLL_EXPORT delegate void DOnRpcRecv(PTR(CProtocolHeader) poHeader, PTR(IRpcArg) poRpcArg);
	QDLL_EXPORT delegate SPromise<SCallRpcRet<PTR(IRpcArg), PTR(IRpcRet)>> DOnRpcCall(PTR(CProtocolHeader) poHeader, PTR(IRpcArg) poRpcArg);

#else

    using DOnProtocolEndPointConnect = std::function<void(CONST_REF(SProtocolEndPoint) rsSrcEndPoint, CONST_REF(SProtocolEndPoint) rsDstEndPoint)>;
    using DOnProtocolEndPointDisconnect = std::function<void(CONST_REF(SProtocolEndPoint) rsSrcEndPoint, CONST_REF(SProtocolEndPoint) rsDstEndPoint)>;
    using DOnProtocolChannelAccepted = std::function<void(UINT64 qwChannelUID)>;
    using DNewProtocolHelper = std::function<CUniquePtr(IProtocolHelper)(CServiceBackendHelper&)>;
    using DOnProtocolChannelClosed = std::function<void(UINT64 qwChannelUID)>;
	using DOnRpcCall = std::function<CPromise<std::unique_ptr<std::vector<UINT8>>>*(CProtocolServiceFrontend&, const CProtocolHeader& roHeader, std::unique_ptr<std::vector<UINT8>>&& poBody)>;

#endif
}

#endif
